<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Coupon;
use App\Models\Country;

class CouponController extends Controller
{
    public function index(){
        $coupons = Coupon::take(10)->get();
        $countries = Country::all();
        if(session('country_id')){
            return redirect(route('coupon.country', session('country_id')));
        }
        return view('coupon.index', compact('coupons', 'countries'));
    }
    public function index_country($id){
        $countries = Country::all();
        $country = Country::where('id', $id) -> first();
        $coupons = $country->coupons()->take(10)->get();
        return view('coupon.index', compact('coupons', 'countries'));
    }

    public function show($id){
        $coupon = Coupon::where('id', $id) -> first();
        return view('coupon.show', compact('coupon'));
    }
}
